
<?php
// DB
define('DB_DRIVER', 'mysql');
define('DB_HOSTNAME', 'localhost');
define('DB_USERNAME', 'katerproru');
define('DB_PASSWORD', 'SW4JoXhjb');
define('DB_DATABASE', 'katerproru');
define('DB_PREFIX', '');

$db = mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD) or die('connect to database failed');
mysql_select_db(DB_DATABASE);
mysql_query("set character_set_client='utf8'");
mysql_query("set character_set_results='utf8'");
mysql_query("set collation_connection='utf8_general_ci'");



$lenght = $_GET['ln'];

$lenght = str_replace(',','.',$lenght);



/*
if((float)$lenght >= 4,5 && (float)$lenght < 5)
{
	$powermax = 70;
	$powermin = 40;
}
elseif((float)$lenght >= 5 && (float)$lenght < 5.5)
{
    $powermax = 90;
	$powermin = 50;	
}
elseif((float)$lenght >= 5.5 && (float)$lenght < 6)
{
    $powermax = 90;
	$powermin = 150;	
}
elseif((float)$lenght >= 6 && (float)$lenght < 7)
{
    $powermax = 200;
	$powermin = 115;	
}
elseif((float)$lenght >= 7)
{
    $powermax = 300;
	$powermin = 200;	
};
*/

if((float)$lenght >= 5.5 && (float)$lenght < 6)
{
    $powermax = 150;
	$powermin = 90;	
}
elseif((float)$lenght >= 6 && (float)$lenght < 7)
{
    $powermax = 200;
	$powermin = 115;	
}
elseif((float)$lenght >= 7)
{
    $powermax = 300;
	$powermin = 200;	
}
elseif((float)$lenght < 5.5)
{
    $powermax = 90;
	$powermin = 40;	
};

switch($_GET['vd']){
case '1' : $model = 'Yamaha'; $prefix = "pr" ; break;
case '2' : $model = 'Suzuki'; $prefix = "prr" ; break;
case '3' : $model = 'Mercury'; $prefix = "prrr" ;  break;
}

$result_y = mysql_query("SELECT DISTINCT
                             product.price, product_description.name, product.weight, product.image 
                       FROM 
                             product_to_category, product, product_description, product_image 
                       WHERE 
                             product.product_id = product_description.product_id
                       AND
                             product.product_id = product_to_category.product_id 
                       AND 
                             product_to_category.category_id = '62'
                       AND  
                             product.weight 
                          BETWEEN
                               $powermin
                             AND
                               $powermax
                                 
                       AND
                             product.model = '$model'
                      LIMIT 3");

/*
$result_s = mysql_query("SELECT 
                             product.price, product_description.name, product.weight 
                       FROM 
                             product_to_category, product, product_description 
                       WHERE 
                             product.product_id = product_description.product_id
                       AND
                             product.product_id = product_to_category.product_id 
                       AND 
                             product_to_category.category_id = '62'
                       AND  
                             product.weight 
                          BETWEEN
                               $powermin
                             AND
                               $powermax
                                 
                       AND
                             product.model = 'Suzuki' 
                      LIMIT 3");

$result_m = mysql_query("SELECT 
                             product.price, product_description.name, product.weight 
                       FROM 
                             product_to_category, product, product_description 
                       WHERE 
                             product.product_id = product_description.product_id
                       AND
                             product.product_id = product_to_category.product_id 
                       AND 
                             product_to_category.category_id = '62'
                       AND  
                             product.weight 
                          BETWEEN
                               $powermin
                             AND
                               $powermax
                                 
                       AND
                             product.model = 'Mercury' 
                      LIMIT 3");

*/

if (!$result_y) {
    die('Неверный запрос: ' . mysql_error());
}

echo '<h1>Моторы:'.$model.'</h1>';

echo '<table border="1" width="100%">';

$i = 0;

while ($row = mysql_fetch_object($result_y)) {
    $i++;
    if($row->name){
			echo '<tr><td>';
			echo '<input onclick="prr()" id="'.$prefix.$i.'" type="checkbox"><label for="'.$prefix.$i.'">'.$row->name.'( '.number_format( $row->price, 0, ',', '' ).' рублей)</label> ';
			echo rtrim(rtrim($row->weight, '0'), '.').' л.с</td>
			<td><a class="colorbox cboxElement" title="Салон Мотопроменад" rel="colorbox" href="/image/cache/'.str_replace('.jpg','-max-600.jpg', $row->image).'"><img width="150px" src="/image/cache/'.str_replace('.jpg','-300x220.jpg', $row->image).'"/></a>';
			echo '</td></tr>';
	}
}


/*
while ($row = mysql_fetch_object($result_s)) {
    $i++;
    echo '<input onclick="prr()" id="pr'.$i.'" type="checkbox"><label for="pr'.$i.'">'.$row->name.'( '.number_format( $row->price, 0, ',', '' ).' рублей)</label><br>';
    echo rtrim(rtrim($row->weight, '0'), '.').' л.с<br>';
}

echo "</td><td>";

while ($row = mysql_fetch_object($result_m)) {
    $i++;
    echo '<input onclick="prr()" id="pr'.$i.'" type="checkbox"><label for="pr'.$i.'">'.$row->name.'( '.number_format( $row->price, 0, ',', '' ).' рублей)</label><br>';
    echo rtrim(rtrim($row->weight, '0'), '.').' л.с<br>';
}

*/
echo "</table>";
/*
"SELECT 
                             product.price, product_description.name, product.weight 
                       FROM 
                             product_to_category, product, product_description 
                       WHERE 
                             product.product_id = product_description.product_id
                       AND
                             product.product_id = product_to_category.product_id 
                       AND 
                             product_to_category.category_id = '62'
                       AND  
                             product.weight 
                          BETWEEN
                               $powermin
                             AND
                               $powermax
                                 
                     GROUP BY 
                             product.model 
                      LIMIT 3" 
*/ 
 



?>
<input type="button" onclick="butClose()" value="Закрыть"/>
<script>
$('.colorbox').colorbox({
	overlayClose: true,
	opacity: 0.5
});
//--></script>

